{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b3353b5f",
   "metadata": {},
   "source": [
    "# 列表的语法：\n",
    "* 1.list.append(obj)——在列表末尾添加新的对象\n",
    "* 2.list.count(obj)——统计某个元素在列表中出现的次数\n",
    "* 3.list.extend(seq)——在列表末尾一次性追加另一个序列中的多个值（用新列表扩展原来的列表）\n",
    "* 4.list.index(obj)——从列表中找出某个值第一个匹配项的索引位置\n",
    "* 5.list.insert(index, obj)——将对象插入列表\n",
    "* 6.list.pop([index=-1])——移除列表中的一个元素（默认最后一个元素），并且返回该元素的值\n",
    "* 7.list.remove(obj)——移除列表中某个值的第一个匹配项\n",
    "* 8.list.reverse()——反向列表中元素\n",
    "* 9.list.sort(cmp=None, key=None, reverse=False)——对原列表进行排序"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79432ef8",
   "metadata": {},
   "source": [
    "## 1.append(增加）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "id": "5a6a6f77",
   "metadata": {},
   "outputs": [],
   "source": [
    "aList = [123,'abc']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "id": "73e716a7",
   "metadata": {},
   "outputs": [],
   "source": [
    "aList.append(2022)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "id": "a8e0c3ff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[123, 'abc', 2022]"
      ]
     },
     "execution_count": 148,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aList"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7e1f5d71",
   "metadata": {},
   "source": [
    "## 2.count（计数）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "id": "e0a33b10",
   "metadata": {},
   "outputs": [],
   "source": [
    "aList = [123, 'abc', 123]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "id": "9ac0802d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 150,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aList.count(123)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "id": "d026fab4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 151,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aList.count('abc')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cc5dffdc",
   "metadata": {},
   "source": [
    "## 3.extend（扩展）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "id": "9fcb9663",
   "metadata": {},
   "outputs": [],
   "source": [
    "aList = [123, 'abc']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "id": "ae48b0f3",
   "metadata": {},
   "outputs": [],
   "source": [
    "bList = [2022, 'hmy']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "id": "25df7848",
   "metadata": {},
   "outputs": [],
   "source": [
    "aList.extend(bList)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "id": "02fe1079",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[123, 'abc', 2022, 'hmy']"
      ]
     },
     "execution_count": 155,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aList"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d11c0c3e",
   "metadata": {},
   "source": [
    "## 4.index(索引)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "id": "e4d47a08",
   "metadata": {},
   "outputs": [],
   "source": [
    "aList = [123,'hmy', 'abc']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "id": "f8d0c0b3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 157,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aList.index( 'hmy' )"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "80c2d268",
   "metadata": {},
   "source": [
    "## 5.insert(插入)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "id": "71aefb9a",
   "metadata": {},
   "outputs": [],
   "source": [
    "aList = [123,'abc']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "id": "0faa3885",
   "metadata": {},
   "outputs": [],
   "source": [
    "aList.insert(2,2022)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "id": "96292cf7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[123, 'abc', 2022]"
      ]
     },
     "execution_count": 160,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aList"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9ecbde0d",
   "metadata": {},
   "source": [
    "## 6.pop(移除——默认最后一个元素）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "id": "c4d9954f",
   "metadata": {},
   "outputs": [],
   "source": [
    "list1 = ['a', 'b', 'c']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "id": "85d370b7",
   "metadata": {},
   "outputs": [],
   "source": [
    "list2=list1.pop(1) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "id": "3eafcc77",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'b'"
      ]
     },
     "execution_count": 163,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list2 # 删除的项为"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "id": "40e568ed",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'c']"
      ]
     },
     "execution_count": 164,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list1 # 列表现在是"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "28314178",
   "metadata": {},
   "source": [
    "## 7.remove(移除——某个值的第一个匹配项）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "id": "1a19c094",
   "metadata": {},
   "outputs": [],
   "source": [
    "aList = [123, 'hmy', 'abc']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "id": "98339fc8",
   "metadata": {},
   "outputs": [],
   "source": [
    "aList.remove('hmy')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "id": "c2c6e4bf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[123, 'abc']"
      ]
     },
     "execution_count": 167,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aList"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9a19ed67",
   "metadata": {},
   "source": [
    "## 8.reverse(反向列表元素）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "id": "defff79c",
   "metadata": {},
   "outputs": [],
   "source": [
    "aList = [123, 'hmy', 'abc']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "id": "0d457c76",
   "metadata": {},
   "outputs": [],
   "source": [
    "aList.reverse()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "id": "e53eff2e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['abc', 'hmy', 123]"
      ]
     },
     "execution_count": 170,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aList"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7b00e11c",
   "metadata": {},
   "source": [
    "## 9.sort（排序）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 171,
   "id": "13381017",
   "metadata": {},
   "outputs": [],
   "source": [
    "aList = ['e', 'a', 'u', 'o', 'i']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "id": "0652892f",
   "metadata": {},
   "outputs": [],
   "source": [
    "aList.sort()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "id": "30601c4c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['a', 'e', 'i', 'o', 'u']\n"
     ]
    }
   ],
   "source": [
    "print(aList)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8fea4a57",
   "metadata": {},
   "source": [
    "| 列表的方法 (共9种）    |         Description      |    使用方法    |  备注  |\n",
    "|------------------|------------------------------|------------------|--------|\n",
    "|  append        |   增加——在列表末尾添加新的对象       | list.append(obj) |   无  |\n",
    "|  count        |    计数——统计某个元素在列表中出现的次数    | list.count(obj)  |   无  |\n",
    "|  extend        |   扩展——在列表末尾一次性追加另一个序列中的多个值 | list.extend(seq)  |  用新列表扩展原来的列表 |\n",
    "|  index        |    索引——从列表中找出某个值第一个匹配项的索引位置      | list.index(obj) |   无  |\n",
    "|  insert        |   插入——将对象插入列表      | list.insert(index, obj) |   无  |\n",
    "|  pop        | 移除——移除列表中的一个元素（默认最后一个元素），并且返回该元素的值  | list2=list1.pop(x) | x为元素在列表中的位置 |\n",
    "|  remove       |  移除——移除列表中某个值的第一个匹配项       |list.remove(obj) |   无  |\n",
    "|  reverse       |   反向——反向列表中元素       | list.reverse() |   无  |\n",
    "|  sort       |  排序——对原列表进行排序       | List.sort()|   无  |"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2083b96b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
